$(function(){
	$("#email").hide();

	$("#type-1").click(function(){
		$("#username").show();
		$("#email").hide();
	});

	$("#type-2").click(function(){
		$("#email").show();	
		$("#username").hide();
	});


	$("#submit").click(function(){
		var sType = "username";
		var sValue = "";
		if($("#type-1").attr("checked"))
		{
			sValue = $("#username").val();
			if(sValue=="")
			{
				$("#forget_password-msg").attr("class", "message-error").html( "请输入用户名" );
				return;
			}
		}
		else
		{
			var sType = "email";
			sValue = $("#email").val();
			if(sValue=="")
			{
				$("#forget_password-msg").attr("class", "message-error").html( "请输入邮箱" );
				return;
			}
		}
		
		var eSubmit = document.getElementById("submit");
		eSubmit.disabled = true;
		
		$("#forget_password-msg").removeClass().html(g_sLoadingImage + "提交中...");

		$.ajax({
			type: "POST",
			url: "./?controller=user&task=ajax_forget_password_save&type="+sType+"&value="+sValue,
			dataType: "json",
			success: function(json){
				
				eSubmit.disabled = false;
				
				if(json.status=="0")
				{
					$("#forget_password-msg").removeClass().html("");
					$("#forget_password-form").html( "<p>"+json.description+"</p>" );
				}
				else
				{
					$("#forget_password-msg").attr("class", "message-error").html( json.description );
				}
			}
		});
		
	});
	
});

